package com.shoothzj.example.storage.h2;

import com.shoothzj.example.storage.api.module.FieldInfo;
import com.shoothzj.example.storage.api.module.FieldJavaType;
import com.shoothzj.example.storage.api.module.PrimaryFieldInfo;
import com.shoothzj.example.storage.api.module.StringFieldExt;

public class H2Util {
    public static String getFieldType(PrimaryFieldInfo primaryFieldInfo) {
        return getFieldType(primaryFieldInfo.getFieldJavaType(), primaryFieldInfo.getStringFieldExt());
    }

    public static String getFieldType(FieldInfo fieldInfo) {
        return getFieldType(fieldInfo.getFieldJavaType(), fieldInfo.getStringFieldExt());
    }

    public static String getFieldType(FieldJavaType fieldJavaType, StringFieldExt stringFieldExt) {
        switch (fieldJavaType) {
            case BOOLEAN:
                return "BOOLEAN";
            case INT:
                return "INTEGER";
            case LONG:
                return "BIGINT";
            case DOUBLE:
                return "DOUBLE";
            case STRING:
                if (stringFieldExt == null) {
                    return "VARCHAR";
                }
                return "VARCHAR(" + stringFieldExt.getMaxLen() + ")";
            case LOCAL_DATE_TIME:
                return "TIMESTAMP";
            default:
                throw new IllegalArgumentException("Not supported yet.");
        }
    }
}
